package com.sskj.hhhjys.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.hhhjys.http.HttpConfig;
import com.sskj.hhhjys.ui.activity.MainActivity;
import com.sskj.lib.bean.AppVersionBean;
import com.sskj.lib.bean.GonggaoBean;
import com.sskj.lib.http.JsonCallBack;


public class MainActivityPresenter extends BasePresenter<MainActivity> {
    public void getGonggao() {
        httpService.getGonggao()
                .execute(new JsonCallBack<HttpData<GonggaoBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<GonggaoBean>> response) {
                        HttpData<GonggaoBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.showGonggao(httpData.getData());

                        }
                    }
                });
    }

    public void getNewVersion() {
        httpService.getVersion()
                .execute(new JsonCallBack<HttpData<AppVersionBean>>(false) {
                    @Override
                    public void onSuccess(Response<HttpData<AppVersionBean>> response) {
                        HttpData<AppVersionBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.onVersionDataSuccess(httpData.getData());
                        } else {
                            getGonggao();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<AppVersionBean>> response) {
                        getGonggao();
                        super.onError(response);
                    }
                });
    }


}
